﻿<UserControl x:Class="ttg_internal.Utilities.UsageVisualizer.View.GlobalUsageTabView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convert="clr-namespace:ttg_internal.Utilities.UsageVisualizer.Converter"
    xmlns:ttg="clr-namespace:ttg_internal.utils;assembly=UtilManager">
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Utilities.Common;component/Styles/DefaultStyles.xaml" />
                <ResourceDictionary Source="/Utilities.Common;component/Styles/CustomStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <!-- Converters -->
            <convert:UsageConverter x:Key="UsageConverter" />

            <!-- Styles -->
            <Style x:Key="DeviceTreeItemStyle" TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="IsExpanded" Value="True" />
            </Style>

            <Style x:Key="DeviceTreeStyle" TargetType="{x:Type TreeView}" BasedOn="{StaticResource {x:Type TreeView}}">
                <Setter Property="AlternationCount" Value="2" />
                <Setter Property="ItemContainerStyle" Value="{StaticResource DeviceTreeItemStyle}" />
            </Style>

            <Style x:Key="InlineText" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
                <Setter Property="FontSize" Value="24" />
                <Setter Property="Margin" Value="3,0,3,0" />
            </Style>

            <!-- Data Templates -->
            <HierarchicalDataTemplate DataType="{x:Type ttg:DeviceInfo}" ItemsSource="{Binding SubSystems}" AlternationCount="0">
                <DockPanel>
                    <StackPanel DockPanel.Dock="Left">
                        <StackPanel Orientation="Horizontal">
                            <!--<Line Y1="0" Y2="10" Stroke="Gray" StrokeThickness="1" VerticalAlignment="Bottom" />-->
                            <TextBlock Style="{StaticResource InlineText}" Text="{Binding Name}" />
                            <TextBlock Style="{StaticResource InlineText}">
                                <TextBlock.Text>
                                    <MultiBinding Converter="{StaticResource UsageConverter}">
                                        <Binding Path="Usage" />
                                        <Binding Path="MaxValue" />
                                        <Binding Path="UnitName" />
                                    </MultiBinding>
                                </TextBlock.Text>
                            </TextBlock>
                        </StackPanel>
                        <!--<Line X1="0" X2="1" Stretch="Fill" Stroke="Gray" StrokeThickness="1" HorizontalAlignment="Stretch" />-->
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Right" Margin="10,0,0,0" DockPanel.Dock="Right">
                        <TextBlock HorizontalAlignment="Center" Text="{Binding Value, ElementName=UsageSlider, StringFormat=\{0:F0\}}" />
                        <Slider x:Name="UsageSlider" Maximum="100" TickPlacement="BottomRight" TickFrequency="5" Width="100" />
                    </StackPanel>
                </DockPanel>
            </HierarchicalDataTemplate>

            <DataTemplate DataType="{x:Type ttg:SubSystemInfo}">
                <StackPanel HorizontalAlignment="Left">
                    <StackPanel Orientation="Horizontal">
                        <!--<Line Y1="0" Y2="10" Stroke="Gray" StrokeThickness="1" VerticalAlignment="Bottom" />-->
                        <TextBlock Style="{StaticResource InlineText}" Text="{Binding Name}" />
                        <TextBlock Style="{StaticResource InlineText}">
                                <TextBlock.Text>
                                    <MultiBinding Converter="{StaticResource UsageConverter}">
                                        <Binding Path="Usage" />
                                        <Binding Path="MaxValue" />
                                        <Binding Path="UnitName" />
                                    </MultiBinding>
                                </TextBlock.Text>
                        </TextBlock>
                    </StackPanel>
                    <!--<Line X1="0" X2="1" Stretch="Fill" Stroke="Gray" StrokeThickness="1" HorizontalAlignment="Stretch" />-->
                </StackPanel>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <TreeView Style="{StaticResource DeviceTreeStyle}" ItemsSource="{Binding Devices}" />
</UserControl>
